import {Event} from "socket.io/dist/socket";
import { isType } from "../utils/utils";

export function middlewares (socket) {
  socket.use((event: Event, next: (err?: Error) => void) => {

    socket.setInviteUser = (members) => {
      if (!socket.inviteUsers) {
        socket.inviteUsers = new Map
      }

      if (isType(members, 'array')) {
        members.forEach(member => {
          socket.inviteUsers.set(member.userId, member)
        })
      } else {
        socket.inviteUsers.set(members.userId, members)
      }

      // console.log(socket.inviteUsers)
    }

    next()
  })
}
